<template>
   <el-dialog title="报工单选择"
      v-if="showFlag"
     :visible.sync="showFlag"
     :modal= false
     width="70%"
     center
   >

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="报工日期" prop="rfworkDate">
        <el-date-picker clearable
          v-model="queryParams.rfworkDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择报工日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="报工人" prop="rfworkNick">
        <el-input
          v-model="queryParams.rfworkNick"
          placeholder="请输入报工人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="rfworkList" highlight-current-row @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
      <el-table-column  width="55" align="center" >
          <template v-slot="scope">
              <el-radio v-model="selectedId" :label="scope.row.rfworkId" @change="handleRowChange(scope.row)">{{""}}</el-radio>
          </template>
      </el-table-column>
      <el-table-column label="报工日期" align="center" prop="rfworkDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rfworkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报工人" align="center" prop="rfworkNick" />
      <el-table-column label="直属领导" align="center" prop="leaderNick" />
      <el-table-column label="类别" align="center" prop="rfwordType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sl_rwork_type" :value="scope.row.rfwordType"/>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    
    <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
        <el-button @click="showFlag=false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listRfwork} from "@/api/sl/rfwork";

export default {
  name: "RfworkSelect",
  dicts: ['sl_rwork_type'],
  data() {
    return {
      showFlag:false,
      // 选中数组
      selectedId: null,
      selectedRow: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报工单表格数据
      rfworkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rfworkDate: null,
        rfworkNick: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询报工单列表 */
    getList() {
      this.loading = true;
      listRfwork(this.queryParams).then(response => {
        this.rfworkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //单击选中
    handleCurrent(row){
      if(row){
          this.selectedRow = row;
      }
    },
    //行双击选中
    handleRowDbClick(row){
      if(row){
        this.selectedRow = row;
        this.$emit('onSelected',this.selectedRow);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if(row){
        this.selectedRow = row;
      }
    },
    confirmSelect(){
      if(this.selectedId == null || this.selectedId == 0){
        this.$notify({
          title:'提示',
          type:'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected',this.selectedRow);
      this.showFlag = false;
    }
  }
};
</script>
